/*
 * lab4.fx
 *
 * Created on 20.11.2009, 20:59:04
 */

package javafx179labs.stepanov.lab4;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.animation.Timeline;
import javafx.scene.input.MouseEvent;
import javafx.scene.transform.Scale;
import javafx.scene.transform.Rotate;

/**
 * @author Евгений
 */

var stSysScale: Number = 1;
var mjCoordX = 600;
var mjLegAng = 0;

var scene: ImageView = ImageView {
                        image: Image {
                                url: "{__DIR__}scene.gif"
                        }
                }

var stSys: ImageView = ImageView {
                x: 300
                y: 560
                image: Image {
                url: "{__DIR__}stereo.gif"
                }
                onMouseClicked: function(evt: MouseEvent):Void{
                stSysAnim.playFromStart();
    }
        }

var stSysR: ImageView = ImageView {
                x: 430
                y: 660
                image: Image {
                url: "{__DIR__}right.gif"
                }
                transforms: [Scale { x : bind stSysScale,
                                     y : bind stSysScale
                                     pivotX : 450,
                                     pivotY : 680,
                                     }

                            ]
        }

var stSysL: ImageView = ImageView {
                x: 315
                y: 660
                image: Image {
                url: "{__DIR__}left.gif"
                }
                transforms: [Scale { x : bind stSysScale,
                                     y : bind stSysScale
                                     pivotX : 340,
                                     pivotY : 680,
                                     }
                            ]
        }

var mjChest: ImageView = ImageView {
                x: bind mjCoordX
                y: 460
                image: Image {
                url: "{__DIR__}chest.gif"
                }
                onMouseClicked: function(evt: MouseEvent):Void{
                mjChestAnim.playFromStart();
    }
        }

var mjLeg1: ImageView = ImageView {
                x: bind mjCoordX + 20
                y: 600
                image: Image {
                url: "{__DIR__}leg1.gif"
                }
                transforms: [
                        Rotate {
                        pivotX : bind mjCoordX + 30,
                        pivotY : 625.0,
                        angle: bind mjLegAng
                        }
                        ]

        }

var mjLeg2: ImageView = ImageView {
                x: bind mjCoordX - 40
                y: 600
                image: Image {
                url: "{__DIR__}leg2.gif"
                }
                transforms: [
                        Rotate {
                        pivotX : bind mjCoordX - 25,
                        pivotY : 645.0,
                        angle: bind -mjLegAng
                        }
                        ]
        }

var stSysAnim: Timeline = Timeline {
                repeatCount: 64
                autoReverse:true
                keyFrames : [
                at(0s){
                    stSysScale => 1;
                    }
                at(200ms){
                    stSysScale => 1.6;
                    }
                ]
        }

var mjChestAnim: Timeline = Timeline {
                repeatCount: 1
                autoReverse:true
                keyFrames : [
                    at(0s){
                    mjCoordX => 600;
                    }
                    at(500ms){
                    mjLegAng => 15;
                    }
                    at(1s){
                    mjLegAng => -15;
                    }
                    at(1500ms){
                    mjLegAng => 15;
                    }
                    at(2s){
                    mjLegAng => -15;
                    }
                    at(2500ms){
                    mjLegAng => 15;
                    }
                    at(3s){
                    mjLegAng => -15;
                    }
                    at(3500ms){
                    mjLegAng => 15;
                    }
                    at(4s){
                    mjLegAng => -15;
                    }
                    at(4500ms){
                    mjLegAng => 0;
                    mjCoordX => 200;
                    }
                ]
        }

Stage {
    title: "Application title"
    width: 800
    height: 786
    scene: Scene {
        content: [scene, stSys, stSysR, stSysL, mjLeg1, mjLeg2, mjChest ]
    }
}